home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / xdme_1.84_src.lha / XDME / Lib / src / BoopsiSupport.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-06  |  4.8 KB  |  205 lines

  1. /* BOOPSI Support Functions */
  2.  
  3. #include <intuition/classes.h>
  4. #include <intuition/intuitionbase.h>
  5. #include <clib/alib_protos.h>
  6. #include <clib/intuition_protos.h>
  7. #include <clib/utility_protos.h>
  8. #include <pragmas/intuition_pragmas.h>
  9. #include <pragmas/utility_pragmas.h>
  10.  
  11. #include <stdarg.h>
  12.  
  13. #include "Definitions.h"
  14.  
  15.  
  16. extern struct IntuitionBase *IntuitionBase;
  17. extern struct Library        *UtilityBase;
  18.  
  19. /* This needs less code than SetGadgetAttr_s_ for a single Attribute */
  20.  
  21. Prototype ULONG SetGadgetAttr (struct Gadget *o, struct Window *w, struct Requester *r, ULONG attrID, ULONG ti_data);
  22. ULONG SetGadgetAttr (struct Gadget *o, struct Window *w, struct Requester *r, ULONG attrID, ULONG ti_data)
  23. {
  24.     return SetGadgetAttrs (o, w, r, attrID, ti_data, TAG_DONE);
  25. } /* SetGadgetAttr */
  26.  
  27.  
  28. /* This needs less code than SetAttr_s_ for a single Attribute */
  29.  
  30. Prototype ULONG SetAttr (Object *o, ULONG attrID, ULONG ti_data);
  31. ULONG SetAttr (Object *o, ULONG attrID, ULONG ti_data)
  32. {
  33.     return SetAttrs (o, attrID, ti_data, TAG_DONE);
  34. } /* SetAttr */
  35.  
  36.  
  37. /* Get multiple Attributes at one time */
  38. /* True, if _ALL_ attributes are got, False if at least one get has failed */
  39.  
  40. Prototype ULONG GetAttrsA (Object *o, struct TagItem *ti);
  41. ULONG GetAttrsA (Object *o, struct TagItem *ti)
  42. {
  43.     ULONG rv = 1;
  44.     struct TagItem *tstate;
  45.     tstate = ti;
  46.     while (ti = NextTagItem(&tstate))
  47.     {
  48.     rv = rv && GetAttr (ti->ti_Tag, o, (ULONG *)ti->ti_Data);
  49.     }
  50.     return rv;
  51. } /* GetAttrsA */
  52.  
  53.  
  54. /* VarArgs Stubs for GetAttrsA */
  55.  
  56. Prototype ULONG GetAttrs (Object *o, ...);
  57. ULONG GetAttrs (Object *o, ...)
  58. {
  59.     ULONG   rv;
  60.     va_list tags;
  61.     va_start(tags, o);
  62.     rv = GetAttrsA (o, (struct TagItem *)tags);
  63.     va_end  (tags);
  64.     return rv;
  65. } /* GetAttrs */
  66.  
  67. /* Shortcuts for some Rootclass Methods ... */
  68.  
  69. Prototype ULONG RemoveObject (Object *m);
  70. ULONG RemoveObject (Object *m)
  71. {
  72.     return DoMethod(m, OM_REMOVE);
  73. } /* RemoveObject */
  74.  
  75. Prototype ULONG AppendObject (Object *m, struct MinList *l);
  76. ULONG AppendObject (Object *m, struct MinList *l)
  77. {
  78.     return DoMethod (m, OM_ADDTAIL, l);
  79. } /* AppendObject */
  80.  
  81. Prototype ULONG RemMember (Object *l, Object *m);
  82. ULONG RemMember (Object *l, Object *m)
  83. {
  84.     return DoMethod(l, OM_REMMEMBER, m);
  85. } /* AddMember */
  86.  
  87. /* hmmm wouldn't it be nice, if we added 2 Args ... Mode & Position */
  88.  
  89. Prototype ULONG AddMember (Object *l, Object *m);
  90. ULONG AddMember (Object *l, Object *m)
  91. {
  92.     return DoMethod(l, OM_ADDMEMBER, m);
  93. } /* AddMember */
  94.  
  95.  
  96.  
  97. static ULONG BoopsiSupport_rootsize = 0;
  98.  
  99. DEFAUTOINIT( BoopsiSupport_Initialize )
  100. {
  101.     Object *o;
  102.     o = NewObject(NULL, "rootclass", TAG_END);
  103.     if (!o)
  104.     {
  105.     BoopsiSupport_rootsize = sizeof (struct _Object);
  106.     }
  107.     else
  108.     {
  109. #    if 0
  110.         /* ---- won't work, sorry ... */
  111.         struct IClass *cl = OCLASS(o);
  112. #        if 1
  113.         BoopsiSupport_rootsize =  cl->cl_InstSize;
  114. #        else
  115.         BoopsiSupport_rootsize = -cl->cl_InstOffset;
  116. #        endif
  117. #    else
  118.         /* ---- slow, but safe ... */
  119.         struct MinList  l;
  120.         struct MinNode *n;
  121.         NewList      ((struct List *)&l);
  122.         AppendObject  (o, &l);
  123.         n               = l.mlh_Head;
  124.         BoopsiSupport_rootsize = (ULONG)o - (ULONG)n;
  125.         RemoveObject  (o);
  126. #    endif
  127.     DisposeObject (o);
  128.     }
  129. } /* BoopsiSupport_Initialize */
  130.  
  131. Prototype struct MinNode *Object2Node (Object *o);
  132. struct MinNode *Object2Node (Object *o)
  133. {
  134.     return o? (struct MinNode *)((ULONG)o - BoopsiSupport_rootsize): NULL;
  135. } /* Object2Node */
  136.  
  137. Prototype Object *Node2Object (struct MinNode *n);
  138. Object *Node2Object (struct MinNode *n)
  139. {
  140.     return n? (Object *)((ULONG)n + BoopsiSupport_rootsize) : NULL;
  141. } /* Node2Object */
  142.  
  143.  
  144. #ifdef TEST
  145. extern int printf (char *, ...);
  146.  
  147. int main (int ac, char ** av)
  148. {
  149.     ULONG zz = 100;
  150.     zz -= (ULONG)Object2Node((APTR)zz);
  151.     printf ("sizeof RootNode = %ld\n", zz);
  152.     return 0;
  153. } /* main */
  154. #endif
  155.  
  156. #if 0
  157.  
  158. extern struct Library *GadToolsBase;
  159.  
  160. int GT_GetGadgetAttr (struct Gadget *gad, Tag tag, ULONG *data)
  161. {
  162.     if (Gad-ToolsBase->lib_Version == 37) {
  163.     switch (tag) {
  164.     /*case GTCB_Checked:
  165.     case GTCY_Labels:
  166.     case GTLV_Labels:
  167.     case GTLV_Top:
  168.     case GTPA_Color:
  169.     case GTPA_ColorOffset:
  170.     case GTPA_ColorTable:
  171.     case GTSC_Top:
  172.     case GTSC_Total:
  173.     case GTSC_Visible:
  174.     case GTSL_Level:
  175.     case GTSL_Max:
  176.     case GTSL_Min:
  177.     case GTTX_Text:*/
  178.  
  179.     case GTLV_Selected:
  180.     case GTCY_Active:
  181.         *data = *((UWORD *)((ULONG)(gad + 1)) + 6));
  182.         break;
  183.     case GTMX_Active:
  184.         *data = *((UWORD *)((ULONG)(gad + 1)) + 38));
  185.         break;
  186.     case GTIN_Number:
  187.         *data = ((struct StringInfo *)gad->SpecialInfo)->LongInt;
  188.         break;
  189.     case GTST_String:
  190.         *data = (ULONG)((struct StringInfo *)gad->SpecialInfo)->Buffer;
  191.         break;
  192.     case GA_Disabled:
  193.         *data = (gad->Flags & GFLG_DISABLED) ? 1: 0;
  194.         break;
  195.     default:
  196.         return 0;
  197.     } /* switch */
  198.     return 1;
  199.     } else {
  200.     return GT_GetGadgetAttrs (gad, NULL, NULL, tag, data, TAG_END);
  201.     } /* if */
  202. } /* GT_GetGadgetAttr */
  203.  
  204. #endif
  205.